﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NAudio;
using NAudio.Wave;
using NAudio.Gui;
using System.IO;

namespace NAudio_Test
{
    public partial class Main : Form
    {
        WaveViewer wf = new NAudio.Gui.WaveViewer();
        public Main()
        {
            InitializeComponent();
        }

        private void btn_Convert_Click(object sender, EventArgs e)
        {

            if (oFD_Main.ShowDialog() == DialogResult.OK)
            {
                tBox_File.Text = oFD_Main.FileName;
                //using (Mp3FileReader reader = new Mp3FileReader(oFD_Main.FileName))
                //{
                //    WaveFileWriter.CreateWaveFile(oFD_Main.FileName.Replace(".mp3", ".wav"), reader);
                //}
                //WaveFileWriter.CreateWaveFile(oFD_Main.FileName.Replace(".mp3", ".wav"), mp3stream);
                waveViewer_Main.WaveStream = new Mp3FileReader(new MemoryStream(File.ReadAllBytes(oFD_Main.FileName)));
                waveViewer_Main.FitToScreen();

                Mp3FileReader mp3stream = new Mp3FileReader(new MemoryStream(File.ReadAllBytes(oFD_Main.FileName)));
                IWavePlayer waveOutDevice;
                waveOutDevice = new WaveOut();
                mp3stream.Position = 0;
                waveOutDevice.Init(mp3stream);
                waveOutDevice.Play();

            }
        }
    }
}
